"use strict";
const common_vendor = require("../common/vendor.js");
const composables_useGlobalMessage = require("../composables/useGlobalMessage.js");
const composables_useGlobalToast = require("../composables/useGlobalToast.js");
const pages = [
  {
    "path": "pages/index/index",
    "type": "home",
    "name": "home",
    "layout": "tabbar",
    "style": {
      "navigationBarTitleText": "首页"
    }
  },
  {
    "path": "pages/beauty-test/index",
    "type": "page"
  },
  {
    "path": "pages/beauty-test/result",
    "type": "page"
  },
  {
    "path": "pages/calorie-camera/index",
    "type": "page"
  },
  {
    "path": "pages/calorie-camera/result",
    "type": "page"
  },
  {
    "path": "pages/love-clinic/index",
    "type": "page"
  },
  {
    "path": "pages/love-clinic/result",
    "type": "page"
  }
];
const subPackages = [
  {
    "root": "subPages",
    "pages": [
      {
        "path": "styles/index",
        "type": "page",
        "name": "styles",
        "style": {
          "navigationBarTitleText": "UnoCSS 演示"
        }
      }
    ]
  }
];
function generateRoutes() {
  const routes = pages.map((page) => {
    const newPath = `/${page.path}`;
    return { ...page, path: newPath };
  });
  if (subPackages && subPackages.length > 0) {
    subPackages.forEach((subPackage) => {
      const subRoutes = subPackage.pages.map((page) => {
        const newPath = `/${subPackage.root}/${page.path}`;
        return { ...page, path: newPath };
      });
      routes.push(...subRoutes);
    });
  }
  return routes;
}
const router = common_vendor._({
  routes: generateRoutes()
});
router.beforeEach((to, from, next) => {
  console.log("🚀 beforeEach 守卫触发:", { to, from });
  if (to.path && from.path) {
    console.log(`📍 导航: ${from.path} → ${to.path}`);
  }
  if (to.name === "demo-protected") {
    const { confirm: showConfirm } = composables_useGlobalMessage.useGlobalMessage();
    console.log("🛡️ 检测到访问受保护页面");
    return new Promise((resolve, reject) => {
      showConfirm({
        title: "守卫拦截演示",
        msg: "这是一个受保护的页面，需要确认后才能访问",
        confirmButtonText: "允许访问",
        cancelButtonText: "取消",
        success() {
          console.log("✅ 用户确认访问，允许导航");
          next();
          resolve();
        },
        fail() {
          console.log("❌ 用户取消访问，阻止导航");
          next(false);
          reject(new Error("用户取消访问"));
        }
      });
    });
  }
  next();
});
router.afterEach((to, from) => {
  console.log("🎯 afterEach 钩子触发:", { to, from });
  if (to.path) {
    console.log(`📄 页面切换完成: ${to.path}`);
  }
  if (to.name === "demo-aftereach") {
    const { show: showToast } = composables_useGlobalToast.useGlobalToast();
    console.log("📊 进入 afterEach 演示页面");
    setTimeout(() => {
      showToast("afterEach 钩子已触发！");
    }, 500);
  }
});
exports.router = router;
